package demo2;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class Teacher implements Writable{
    private String name;
    private int age;

    /*
        1.写跟读的类型要一致
        2.写跟读的顺序要一致
        3.读取之后记得给属性赋值
    */

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        // 序列化
        dataOutput.writeUTF(name);
        dataOutput.writeInt(age);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        // 反序列化
        name = dataInput.readUTF();
        age = dataInput.readInt();
    }

    public Teacher() {
    }

    public Teacher(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
